import DataColumn from './dataColumn.js'
export default class DataColumnEnum extends DataColumn {
	
	enumItems = [];
	constructor (name, enumItems) {
		super(name);
		if (enumItems == undefined || enumItems == "") {
			alert("DataColumn"+name+"枚举项不允许为空");
		} else {
			for (let key in enumItems) {
				if (enumItems[key] == undefined) {
					alert("枚举项"+enumItems[key]+"错误，枚举值不允许为空")
				} else {
					this.enumItems.push({name:key, value:enumItems[key], label:key})
				}
			}
			this.setAlignment("Center");
			this.setDisplayLength(10);
		}
	}

	getEnumItems() {
		return this.enumItems;
	}
	
	getDefaultValue() {
		if (this.enumItems == undefined) {
			return 0;
		}
		
		return this.enumItems[0].value;
	}
	
	getItemLabel(itemValue) {
		const enumItemOptional = this.enumItems.filter(item => {
			return item.label === itemValue
		})
		if (Object.keys(enumItemOptional).length) {
			return this.enumItemOptional.label;
		}
		return null;
	}
	
	getDataType() {
		return "TypeEnum";
	}
}